package net.tp.algo.graph;

/**
 *
 *
 * <p>Graph.</p>
 *
 * <p>For simplicity and clarity of many algorithms, graph nodes are represented as 0-based array of numbers. For a generic graph, do the mapping among the nodes to numbers and do algorithms.
 * </p>
 *
 *
 */
public interface Graph {

    /**
     * Number of vertices
     * @return number of vertices
     */
    public int order();

    /**
     * Number of edges
     * @return number of edges
     */
    public int size();

    /**
     * List of vertices.
     * @return list of vertices.
     */
    public Iterable<Integer> vertices();

    /**
     * List of edges
     * @return List of edges
     */
    public Iterable<Edge> edges();


    /**
     * Out-edges from a particular vertex.
     * @param u the vertex
     * @return out-edges
     */
    public Iterable<Integer> adjacents(int u);

    /**
     * Out-edges from a particular vertex.
     * @param u the vertex
     * @return out-edges
     */
    public Iterable<Edge> edges(int u);

    /**
     * Degree of a vertex. For directed graph, this is the outdegree of a vertex.
     * @param u the vertex
     * @return degree
     */
    public int degree(int u);

    public static interface Edge {

        public int either();

        public int other(int u);

        public double weight();

        /**
         * Capacity is to solve network-flow problems.
         * @return capacity
         */
        default public double capacity() { return weight(); }

        public double flow();

        public void setFlow(double flow);

    }
}
